package com.sbox.album;

import com.sbox.album.model.AlbumContext;
import com.sbox.widget.TabButton;

import android.app.TabActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;

public class AlbumsActivity extends TabActivity implements TabHost.TabContentFactory {
    private TabHost mTabHost = null;    
    private LayoutInflater mInflater = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_main);
        
        mInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        
        mTabHost = this.getTabHost();        
        
        AlbumContext.init(this.getApplicationContext());
    }
    
    @Override
    public void onResume()
    {
    	super.onResume();
    	initTabs();
    }
    
    @Override
    public View createTabContent(String tag) {
    	
    	View v = null;
        if ( tag == getText(R.string.str_tab_albums) )
        {
        	AlbumsView albumsView = (AlbumsView)mInflater.inflate(R.layout.view_albums, null);
        	albumsView.init(this);
        	v=albumsView;
        }
        else if (tag == getText(R.string.str_tab_edit) )
        	return mInflater.inflate(R.layout.view_edit, null);
        else if (tag == getText(R.string.str_tab_settings) )
        	return mInflater.inflate(R.layout.view_settings, null);
        else if (tag == getText(R.string.str_tab_more) )
        	return mInflater.inflate(R.layout.view_more, null);
        
        return v;
    }
    
    private void initTabs()
    {    	
    	mTabHost.clearAllTabs();
    	
    	initTab(R.string.str_tab_albums, R.drawable.bg_tab_albums, R.layout.view_albums);
    	initTab(R.string.str_tab_edit, R.drawable.bg_tab_edit, R.layout.view_edit);
    	initTab(R.string.str_tab_settings, R.drawable.bg_tab_settings, R.layout.view_settings);
    	initTab(R.string.str_tab_more, R.drawable.bg_tab_albums, R.layout.view_more);
    }
    
    private void initTab(int tabTextId, int tabImageId, int viewId)
    {
    	TabButton tab = null;
    	TabHost.TabSpec spec = null;
    	
    	tab = (TabButton)mInflater.inflate(R.layout.tab_item, null);
    	tab.getTextView().setText(getString(tabTextId));
    	tab.getImageView().setImageResource(tabImageId);
    	
    	spec = mTabHost.newTabSpec(getString(tabTextId));
    	spec.setIndicator(tab);
    	spec.setContent(this);
    	
    	mTabHost.addTab(spec);
    }
}